package com.hlcl.huaji.view;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.elcl.activity.BaseActivity;
import com.elcl.network.AppContext;
import com.elcl.util.StringUtils;
import com.elcl.util.viewutils.WindowUtils;
import com.google.gson.reflect.TypeToken;
import com.hlcl.huaji.R;
import com.hlcl.huaji.model.LoginResponse;
import com.hlcl.huaji.model.LoginResult;

/**
 * Created by lichunlin on 2018/5/25.
 * 地址列表
 */

public class AddressListActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_address_list);

        WindowUtils windowUtils = new WindowUtils();
        windowUtils.fullScreen(AddressListActivity.this);
        getUserInfo();
        initView();
    }

    private void getUserInfo() {
        String userInfo = AppContext.getUerInfo();
        if (StringUtils.isNotBlank(userInfo)) {
            LoginResult loginResult = gson.fromJson(userInfo, new TypeToken<LoginResult>() {
            }.getType());
            if (null != loginResult) {
                LoginResponse loginResponse = loginResult.getjData();
                if (null != loginResponse) {
                    setText(R.id.tv_name,loginResponse.getUserName());
                    setText(R.id.tv_phone,loginResponse.getPhone());
                    setText(R.id.tv_address,loginResponse.getAdress());
                }
            }
        }
    }

    private void initView() {
        setListener(R.id.tv_edt_address, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(AddressListActivity.this,AddressModifyActivity.class);
                startActivityForResult(intent,0x111);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK){
            if (requestCode == 0x111){
                getUserInfo();
            }
        }
    }

    @Override
    protected void praseJson(int reqId, String json) {



    }
}
